﻿using UnityEngine;
using System.Collections.Generic;

public class FotoScript : MonoBehaviour 
{
	float processDuration = 5f;
	float duration;
	List<GameObject> npcList;
	GameObject ok;
	
	void Start()
	{
		npcList = new List<GameObject>();
		ok = this.transform.FindChild("Ok").gameObject;
		ok.SetActive(false);
		duration = processDuration;
	}
	
	void Update()
	{
		if(npcList.Count > 0 && npcList[0].GetComponent<NPCScript>().NPCState == NPCScript.NPC_ACTION_STATE)
		{
			duration -= Time.deltaTime;
			if(duration <= 0)
			{
				ok.SetActive(true);
				npcList[0].GetComponent<NPCScript>().NPCState = NPCScript.NPC_WAIT_STATE;
				npcList[0].GetComponent<NPCScript>().ProcedureState = NPCScript.PENGAMBILAN_STATE;
				duration = processDuration;
			}
		}
		//Debug.Log(npcList.Count);
	}
	
	public void AddNPC(GameObject param)
	{
		param.transform.position = new Vector3(this.transform.position.x + 1.5f + NPCCount * -1f,
		                                       this.transform.position.y,
		                                       5);
		npcList.Add(param);
		if(npcList.Count == 1)
		{
			npcList[0].GetComponent<NPCScript>().NPCState = NPCScript.NPC_ACTION_STATE;
		}
	}
	
	public void RemoveNPC(GameObject param)
	{
		npcList.Remove(param);
		this.ok.SetActive(false);
		if(npcList.Count > 0)
		{
			foreach(GameObject i in npcList)
			{
				i.transform.position = new Vector3(i.transform.position.x + 1f ,
				                                   this.transform.position.y,
				                                   5);
			}
			npcList[0].GetComponent<NPCScript>().NPCState = NPCScript.NPC_ACTION_STATE;
		}
	}
	
	public int NPCCount
	{
		get{return this.npcList.Count;}
	}
}
